<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期对象的使用</title>
</head>

<body>
    <div></div>
    <script>
        setInterval(function () {
            const date = new Date()
            // document.write(`${date.getFullYear()}年`)
            // // 月份从0开始，获取时 +1
            // document.write(`${date.getMonth() + 1}月`)
            // document.write(`${date.getDate()}日 `)
            // document.write(` ${date.getHours().toString().padStart(2,0)}时`)
            // document.write(`${date.getMinutes().toString().padStart(2,0)}分`)
            // document.write(`${date.getSeconds().toString().padStart(2,0)}秒`)
            // document.write(` 星期${date.getDay()}<br>`)
            const div = document.querySelector('div')
            div.innerHTML = date.toLocaleString() // 2024/6/25 23:34:29
            div.innerHTML = date.toLocaleDateString() // 2024/6/25
            div.innerHTML = date.toLocaleTimeString() // 23:34:29
            
        },1000)

    </script>
</body>

</html>